#include <vector>
#include <iostream>
#include <sstream>

void dfs(std::vector<std::vector<int>> &link_map,
         std::vector<bool> &vis_map, int i)
{
    if (vis_map[i])
        return;

    vis_map[i] = true;
    for (int j = 0; j < vis_map.size(); j++)
    {
        if (!vis_map[j])
        {
            if (link_map[i][j] == 1)
            {
                dfs(link_map, vis_map, j);
            }
        }
    }
}

int main()
{
    std::vector<std::vector<int>> link_map;

    std::string s;
    while (std::getline(std::cin, s))
    {
        std::istringstream iss(s);
        std::vector<int> tl;
        int n;
        while (iss >> n)
        {
            tl.push_back(n);
            // std::cout << n << std::endl;
        }
        link_map.push_back(tl);
    }

    std::vector<bool> vis_map(link_map.size(), false);

    int cnt = 0;
    for (int i = 0; i < vis_map.size(); i++)
    {
        if (!vis_map[i])
        {
            dfs(link_map, vis_map, i);
            cnt++;
        }
    }

    std::cout << cnt << std::endl;
    return 0;
}